package com.zy.mc_module.utils;

import android.net.Uri;
import android.text.TextUtils;

import com.zy.mc_module.common.Constant;
import com.zy.mc_module.mvp.bean.UserBean;

import java.math.BigDecimal;

/**
 * Created on 18/12/3
 * 用户信息工具类
 */
public class UserUtils {

    private static UserBean userBean;

    /**
     * 保存用户数据
     */
    public static void saveUser(UserBean bean) {
        SPUtil.putObject(Constant.USER_KEY, bean);
    }

    public static void setUserBean(UserBean bean){
        userBean = bean;
    }

    /**
     * 获取用户数据
     */
    public static UserBean getUser() {
        if (userBean != null) return userBean;
        return SPUtil.getObject(Constant.USER_KEY, UserBean.class);
    }

    /***
     * 用户是否登录
     */
    public static boolean isLogin() {
        return null != getUser();
    }

    public static void setImg(String imgPath) {
        UserBean userBean = getUser();
        if (null != userBean) {
            userBean.setHeadImage(imgPath);
            saveUser(userBean);
        }
    }
    /**
     * 获取用户uid
     */
    public static long getUid() {
        UserBean bean = getUser();
        if (null != bean && 0 != bean.getId()) {
            return bean.getId();
        }
        return -1;
    }

    /**
     * todo edit
     * 获取用户手机号
     */
    public static String getTel() {
        UserBean bean = getUser();

        return "";
    }

    /**
     * 用户的头像
     */
    public static String getHeadImg() {
        UserBean bean = getUser();
        if (null != bean) {
            return bean.getHeadImage();
        }
        return "";
    }

    /***
     * 用户退出登录
     */
    public static void exitLogin() {//oppotuisong appshangxiantisheng
        userBean = null;
        SPUtil.removeObje("imUserId");
        SPUtil.removeObje(Constant.USER_KEY);
        SPUtil.removeList(Constant.SHOPCAR_DATA);
        SPUtil.removeObje(Constant.USER_H5_KEY);
        SPUtil.putBoolean("workbench_access", false);
    }
}